﻿
using Aop.Api;
using Aop.Api.Domain;
using Aop.Api.Request;
using Aop.Api.Response;
using DAL;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Shop.Web.Controllers
{
    public class ZhiFuController : Controller
    {
        // GET: ZhiFu
        public ActionResult Index(Order order,int ProductId1,int Count)
        {
            OrderService.AddOrder(order, ProductId1, Count);

            DefaultAopClient client = new DefaultAopClient(config.gatewayUrl, config.app_id, config.private_key, "json", "1.0", config.sign_type, config.alipay_public_key, config.charset, false);

            // 外部订单号，商户网站订单系统中唯一的订单号
            string OrderId = order.OrderId;
            // 订单名称
            string _ProductName = order.ProductName;

            // 付款金额
            string total_amount = order.ToPrice.ToString();
            //string _CustId = CustId;
            //string _ProductPrth = ProductPrth;
            //string _IsTake = IsTake;
            //string _Count = Count; 
            //string _State = State;
            //string _OrderTime = OrderTime;
            //string _IsFah = Price;

            // 商品描述
            string body = "10";

            

            // 组装业务参数model
            AlipayTradePagePayModel model = new AlipayTradePagePayModel();
            model.Body = body;
            model.Subject = _ProductName;
            model.TotalAmount = total_amount;
            model.OutTradeNo = OrderId;
            model.ProductCode = "FAST_INSTANT_TRADE_PAY";

            AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
            // 设置同步回调地址
            request.SetReturnUrl("http://localhost:64132/Order/Index?OrderId="+OrderId);
            // 设置异步通知接收地址
            request.SetNotifyUrl("http://localhost:64132/Order/Index");
            // 将业务model载入到request
            request.SetBizModel(model);

           

            AlipayTradePagePayResponse response = null;
            try
            {
                response = client.pageExecute(request, null, "post");
                Response.Write(response.Body);
               
            }
            catch (Exception exp)
            {
                throw exp;
            }
           
            return Content("");

        }


        //public ActionResult Test1()
        //{
        // 
        //  return Content("支付完成");
        //}
    }

}